package com.dhnsoft.education.controller.edu.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dhnsoft.education.entity.edu.EduCourse;
import com.dhnsoft.education.entity.edu.EduTeacher;
import com.dhnsoft.education.service.edu.EduCourseService;
import com.dhnsoft.education.service.edu.EduTeacherService;
import com.dhnsoft.education.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Description
 * @ClassName TeacherFrontController
 * @Author dhn
 * @date 2022.04.09 16:10
 */
@RestController
@RequestMapping("/eduservice/teacherFront")
//@CrossOrigin
public class TeacherFrontController {

    @Autowired
    private EduTeacherService teacherService;

    @Autowired
    private EduCourseService courseService;

    //讲师分页查询接口
    @GetMapping("/getTeacherFrontPageList/{page}/{limit}")
    public R getTeacherFrontPageList(@PathVariable Long  page, @PathVariable Long  limit ){
        Page<EduTeacher> teacherPage = new Page<>(page, limit);
        Map<String,Object> map = teacherService.getTeacherPageList(teacherPage);
        return R.ok().data(map);
    }

    //2.讲师详情功能
    @GetMapping("getTeacherFrontInfo/{teacherId}")
    public R getTeacherFrontInfo(@PathVariable String teacherId){
        //1.根据讲师id查询讲师的基本信息
        EduTeacher teacherInfo = teacherService.getById(teacherId);
        //2.根据讲师id查询自己讲授的课程信息
        QueryWrapper<EduCourse> wrapper = new QueryWrapper<>();
        wrapper.eq("teacher_id",teacherId);
        List<EduCourse> courseList = courseService.list(wrapper);

        return R.ok().data("teacher",teacherInfo).data("courseList",courseList);
    }

}
